package org.example.juc.lock.demo;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchTest {
    static CountDownLatch countDownLatch = new CountDownLatch(3);
    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"开始");
            countDownLatch.countDown();
            System.out.println(Thread.currentThread().getName()+"结束");
        });
        Thread t2 = new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"开始");
            countDownLatch.countDown();
            System.out.println(Thread.currentThread().getName()+"结束");
        });
        Thread t3 = new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"开始");
            countDownLatch.countDown();
            System.out.println(Thread.currentThread().getName()+"结束");
        });
        t1.start();
        t2.start();
        t3.start();
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
